package doorwifi.wd.patientsation.peripheral.mainapp.Activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;

import doorwifi.wd.patientsation.peripheral.mainapp.Bean.illnessRoom;
import doorwifi.wd.patientsation.peripheral.mainapp.R;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.illnessDoorAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.utils.DividerGridItemDecoration;

@ContentView(R.layout.activity_request_trusteeship)
public class requestTrusteeshipActivity extends AppCompatActivity implements illnessDoorAdapter.illnessDoorItemOnclickListener,View.OnClickListener{


    @ViewInject(R.id.trusteeship_recyclerview)
    private RecyclerView trusteeship_recyclerview;
    @ViewInject(R.id.trusteeship_setting)
    private Button trusteeship_setting;
    @ViewInject(R.id.xh_main_trusteeship)
    private TextView xh_main_trusteeship;
    @ViewInject(R.id.xh_main_trusteeship1)
    private TextView xh_main_trusteeship1;
    @ViewInject(R.id.xh_main_trusteeship2)
    private TextView xh_main_trusteeship2;
    @ViewInject(R.id.popuwindow_determine)
    private TextView popuwindow_determine;


    private illnessDoorAdapter illnessDoorAdapter;
    private ArrayList<illnessRoom> roomList;
    private illnessRoom room;
    private PopupWindow mpopupwindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        setContentView(R.layout.activity_request_trusteeship);
        x.view().inject(this);
        initView();
        WindowManager wm = this.getWindowManager();

        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();

        Log.w("-----------",width+"========="+height+"====");//1024   600

    }

    private void initView() {
        getDepartmentData();
        trusteeship_recyclerview.setLayoutManager(  new GridLayoutManager(this,3));
        illnessDoorAdapter = new illnessDoorAdapter(this,roomList);
        trusteeship_recyclerview.setAdapter(illnessDoorAdapter);
        trusteeship_recyclerview.addItemDecoration(new DividerGridItemDecoration(this));
        illnessDoorAdapter.setillnessDoorOnItemClickListener(this);
        trusteeship_setting.setOnClickListener(this);

    }

    private void getDepartmentData() {
        roomList = new ArrayList<illnessRoom>();
        for(int i = 1; i < 12; i ++){
            room = new illnessRoom();
            room.setIllnessNumber(i+"科室");//Department
            roomList.add(room);
        }
    }

    @Override
    public void onSickDoorItemClick(View view, int position) {

//        UIUtils.showToast(requestTrusteeshipActivity.this,position+"");
        illnessDoorAdapter.setPosition(position);
        illnessDoorAdapter.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.trusteeship_setting:
                trusteeship_setting.setBackgroundColor(Color.GRAY);
                xh_main_trusteeship.setVisibility(View.VISIBLE);
                xh_main_trusteeship1.setVisibility(View.VISIBLE);
                xh_main_trusteeship2.setVisibility(View.VISIBLE);
                showPopoWindow();
                break;
            case R.id.popuwindow_determine:
                mpopupwindow.dismiss();
                startActivity(new Intent(requestTrusteeshipActivity.this,trusteeshipViewActivity.class));
                finish();
                break;
        }

    }
    private void showPopoWindow(){
        View contentview = LayoutInflater.from(this).inflate(R.layout.xh_trusteeship_popuwindow_layout, null);
        mpopupwindow = new PopupWindow(contentview, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
//        UIUtils.setPopuWindowBackground(this,mpopupwindow);
        popuwindow_determine = (TextView) contentview.findViewById(R.id.popuwindow_determine);
        mpopupwindow.setOutsideTouchable(true);
        mpopupwindow.setSplitTouchEnabled(true);
        popuwindow_determine.setOnClickListener(this);
        // 显示PopupWindow
        View rootview = LayoutInflater.from(this).inflate(R.layout.activity_request_trusteeship, null);
        mpopupwindow.showAtLocation(rootview, Gravity.CENTER, 0, 0);
    }
}
